<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        body {}

        footer {
            position: absolute;
            bottom: 0;
            height: 200px;
            width: 100%;
        }

        button {
            margin: 5px;
            padding: 5px;
            background-color: green;
            color: #fff;
            border-radius: 5px;
        }
    </style>
</head>

<body>
    <footer>
        <button type="button" name="button" onclick="initPusherL()">initPusherL</button>
        <button type="button" name="button" onclick="startPreviewL()">startPreviewL</button>
        <button type="button" name="button" onclick="startPushL()">startPushL</button>
        <button type="button" name="button" onclick="stopPushL()">stopPushL</button>
        <button type="button" name="button" onclick="pauseL()">pauseL</button>
        <button type="button" name="button" onclick="resumeL()">resumeL</button>
        <button type="button" name="button" onclick="restartPushL()">restartPushL</button>
        <button type="button" name="button" onclick="reconnectPushL()">reconnectPushL</button>
        <button type="button" name="button" onclick="destroyL()">destroyL</button>
        <button type="button" name="button" onclick="setMuteL()">setMuteL</button>
        <button type="button" name="button" onclick="switchCameraL()">switchCameraL</button>
        <button type="button" name="button" onclick="setFlashL()">setFlashL</button>
        <button type="button" name="button" onclick="setPreviewMirrorL()">setPreviewMirrorL</button>
        <button type="button" name="button" onclick="getFsPath()">getFsPath</button>
        <button type="button" name="button" onclick="startScreenCaptureL()">startScreenCaptureL</button>
        <button type="button" name="button" onclick="stopScreenCaptureL()">stopScreenCaptureL</button>
        <button type="button" name="button" onclick="startCameraL()">startCameraL</button>


    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var alivcLivePusher = null;
    var pushRUL = 'rtmp://alivclivepusher.bjmnkj.cn/meiniao/meiniaosn?auth_key=1640224527-0-0-9fa67967125f458e73195d7d7717da08';
    var fsPath = '';
    apiready = function () {
        alivcLivePusher = api.require('alivcLivePusher');
    };
    //初始化推流
    function initPusherL() {
        alivcLivePusher.initPusher({
            resolution: 540,
            initialVideoBitrate: 800,
            targetVideoBitrate: 800,
            minVideoBitrate: 400,
            qualityMode: 'ResolutionFirst',
            beautyMode: 'normal',
            previewOrientation: 'PORTRAIT',
            externMainStream: true,
            fps: 20,
            videoOnly: true,
            cameraType: 'front' //back
        }, function (ret) {
            alert(JSON.stringify(ret) + '----->初始化成功');
        })
    }
    //预览
    function startPreviewL() {
        alivcLivePusher.startPreview({
            rect: {
                x: 0, //（可选项）数字类型；模块左上角的 x 坐标（相对于所属的 Window 或 Frame）；默认值：0
                y: 0, //（可选项）数字类型；模块左上角的 y 坐标（相对于所属的 Window 或 Frame）；默认值：0
                w: (api.frameHeight - 200) * (2 / 3), //(可选项)数字类型;模块宽度（相对于所属的 Window 或 Frame;默认300
                h: api.frameHeight - 200//(可选项)数字类型;模块高度（相对于所属的 Window 或 Frame;默认300
            },
            fixedOn: api.frameName,
            fixed: false
        }, function (ret) {
            alert(JSON.stringify(ret));
        })
    }
    //开始推流
    function startPushL() {
        alivcLivePusher.startPush({
            url: pushRUL
        }, function (ret) {
            alert(JSON.stringify(ret));
        })
    }
    //停止推流
    function stopPushL() {
        alivcLivePusher.stopPush();
    }
    //暂停推流
    function pauseL() {
        alivcLivePusher.pause();
    }
    //恢复推流
    function resumeL() {
        alivcLivePusher.resume();
    }
    //重新开始推流
    function restartPushL() {
        alivcLivePusher.restartPush();
    }
    //推流重连
    function reconnectPushL() {
        alivcLivePusher.reconnectPush();
    }
    //销毁推流
    function destroyL() {
        alivcLivePusher.destroy();
    }
    //设置静音
    function setMuteL() {
        alivcLivePusher.setMute({
            isMute: true
        });
    }
    //切换摄像头
    function switchCameraL() {
        alivcLivePusher.switchCamera();
    }
    //设置闪光灯
    function setFlashL() {
        alivcLivePusher.setFlash({
            isFlash: true
        });
    }
    //镜像预览
    function setPreviewMirrorL() {
        alivcLivePusher.setPreviewMirror({
            isMirror: true
        });
    }
    //打开美颜
    function setBeautyOnL() {
        alivcLivePusher.setBeautyOn({
            isBeautyOn: true
        });
    }
    //录屏
    function startScreenCaptureL() {
        alivcLivePusher.startScreenCapture({
            url: pushRUL,
            networkPoorImage: fsPath,
            pausePushImage: fsPath
        }, function (ret) {
            alert(JSON.stringify(ret));
            startCameraL();
        });
    }
    function stopScreenCaptureL() {
        alivcLivePusher.stopScreenCapture(function (ret) {
            alert(JSON.stringify(ret));
        });
    }
    function startCameraL() {
        alivcLivePusher.startCamera({
            rect: {
                x: 0,
                y: 0,
                w: 200,
                h: 200
            }
        }, function (ret) {
            alert(JSON.stringify(ret));
        });
    }
    function getFsPath() {
        api.getPicture({
            sourceType: 'library',
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: true,
            quality: 50,
            targetWidth: 100,
            targetHeight: 100,
            saveToPhotoAlbum: false
        }, function (ret, err) {
            if (ret) {
                fsPath = ret.data
                console.log(fsPath);
            } else {
                alert(JSON.stringify(err));
            }
        });

    }
</script>

</html>